import { Component, OnInit } from '@angular/core';

declare var form: any;

@Component({
  templateUrl: './data.syn.component.html'
})
export class DataSynComponent implements OnInit {

  fs: any = null;
  logfs: any = null;
  visible = false;
  all: any;
  state: any;

  constructor() {
    this.fs = new form.FormSimpleService('datasyn', {
      orderObject: { addDate: 1 },
      keyField: 'id'
    });
    this.fs.loadData(true);

    this.logfs = new form.FormSimpleService('datasynlog', {
      orderObject: { addDate: 1 },
      keyField: 'id'
    });
  }

  ngOnInit() {
  }

  iniFsData() {
    if (this.all === 'true') {
      this.fs.queryObject.all = true;
    } else if (this.all === 'false') {
      this.fs.queryObject.all = false;
    } else {
      this.fs.queryObject.all = 'nullItem';
    }
    this.fs.loadData(true);
  }

  resetFs() {
    this.all = null;
    this.fs.resetQueryObject();
    this.iniFsData();
  }

  iniLogFsData() {
    if (this.state === 'true') {
      this.logfs.queryObject.state = true;
    } else if (this.state === 'false') {
      this.logfs.queryObject.state = false;
    } else {
      this.logfs.queryObject.state = 'nullItem';
    }
    this.logfs.loadData(true);
  }

  resetLogFs() {
    this.state = null;
    this.logfs.resetQueryObject();
    this.iniLogFsData();
  }

  // 打开弹窗详细信息
  open(id): void {
    this.visible = true;
    this.logfs.defaultQueryObject = { 'synid:=': id };
    this.logfs.loadData(true);
  }

  // 关闭弹窗
  close(): void {
    this.visible = false;
  }
}
